package com.customers.controller;

import com.alibaba.fastjson2.JSON;
import com.customers.entity.Customer;
import com.customers.service.CustomerService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/editContactForm")
public class EditContactFormServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String contactJson = request.getParameter("Contact");
        Customer contact  = JSON.parseObject(contactJson,Customer.class);
        try {
            CustomerService customerService = (CustomerService) request.getServletContext().getAttribute("CustomerService");
            String sql = "contactUp";
            customerService.editContact(contact,sql);
//            EditContactService.editContact(contact);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
